package com.oot2d.util;

import com.oot2d.event.EventManager;
import org.newdawn.slick.*;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.gui.TextField;

public class Console extends TextField {
    public Console(GameContainer gc, Font f)
    {
        super(gc, f, 5, 295, 470, 20, new ComponentListener() {
            public void componentActivated(AbstractComponent source) {
            }
        }
        );

        this.setBorderColor(null);
        this.setTextColor(new org.newdawn.slick.Color(255, 255, 255));

    }

    public void keyPressed(int key, char c)
    {
        if (key == Input.KEY_GRAVE) {
            setText("");
            return;
        }

        if (key == Input.KEY_ENTER) {
            EventManager.runScript(getText());
            setText("");
            toggle();
            return;
        }

        super.keyPressed(key, c);
    }

    public void toggle()
    {
        setFocus(!hasFocus());
    }

    public void render(GameContainer gc, org.newdawn.slick.Graphics g)
    {
        if (!hasFocus())
            return;

        g.setColor(new org.newdawn.slick.Color(255, 255, 255));
        super.render(gc, g);
    }
}
